package com.cloud.bc.service.impl;

import com.cloud.bc.model.entity.BcSingleMates;
import com.cloud.bc.mapper.BcSingleMatesMapper;
import com.cloud.bc.service.BcSingleMatesService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 单身择偶标准
 *
 * @author douhaichao code generator
 * @date 2021-01-04 17:56:40
 */
@Service
@AllArgsConstructor
public class BcSingleMatesServiceImpl extends ServiceImpl<BcSingleMatesMapper, BcSingleMates> implements BcSingleMatesService {

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    @Override
    public BcSingleMates selectOne(BcSingleMates req) {
        QueryWrapper queryWrapper = new QueryWrapper<BcSingleMates>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<BcSingleMates> selectAll(BcSingleMates req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<BcSingleMates> selectPage(Page page, BcSingleMates req) {
        IPage<BcSingleMates> list = baseMapper.selectPage(
                page,
                new QueryWrapper<BcSingleMates>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<BcSingleMates> selectPageByLike(Page page, BcSingleMates req) {
        QueryWrapper queryWrapper = new QueryWrapper();

        if (null != req.getUserId()) {
            queryWrapper.eq("user_id", req.getUserId());
        }

        if (null != req.getMateGender()) {
            queryWrapper.eq("mate_gender", req.getMateGender());
        }

        if (!StrUtil.isEmpty(req.getMateAge())) {
            queryWrapper.like("mate_age", req.getMateAge());
        }

        if (null != req.getMateAgeMin()) {
            queryWrapper.eq("mate_age_min", req.getMateAgeMin());
        }

        if (null != req.getMateAgeMax()) {
            queryWrapper.eq("mate_age_max", req.getMateAgeMax());
        }

        if (!StrUtil.isEmpty(req.getMateHeight())) {
            queryWrapper.like("mate_height", req.getMateHeight());
        }

        if (null != req.getMateHeightMin()) {
            queryWrapper.eq("mate_height_min", req.getMateHeightMin());
        }

        if (null != req.getMateHeightMax()) {
            queryWrapper.eq("mate_height_max", req.getMateHeightMax());
        }

        if (null != req.getMateIncome()) {
            queryWrapper.eq("mate_income", req.getMateIncome());
        }

        if (!StrUtil.isEmpty(req.getMateIncomeCn())) {
            queryWrapper.like("mate_income_cn", req.getMateIncomeCn());
        }

        if (null != req.getMateEducation()) {
            queryWrapper.eq("mate_education", req.getMateEducation());
        }

        if (!StrUtil.isEmpty(req.getMateEducationCn())) {
            queryWrapper.like("mate_education_cn", req.getMateEducationCn());
        }

        if (!StrUtil.isEmpty(req.getMateDistrict())) {
            queryWrapper.like("mate_district", req.getMateDistrict());
        }

        if (!StrUtil.isEmpty(req.getMateDistrictCn())) {
            queryWrapper.like("mate_district_cn", req.getMateDistrictCn());
        }

        if (null != req.getMateMarriage()) {
            queryWrapper.eq("mate_marriage", req.getMateMarriage());
        }

        if (!StrUtil.isEmpty(req.getMateMarriageCn())) {
            queryWrapper.like("mate_marriage_cn", req.getMateMarriageCn());
        }

        if (null != req.getMateChildren()) {
            queryWrapper.eq("mate_children", req.getMateChildren());
        }

        if (!StrUtil.isEmpty(req.getMateChildrenCn())) {
            queryWrapper.like("mate_children_cn", req.getMateChildrenCn());
        }

        if (null != req.getMateConstellation()) {
            queryWrapper.eq("mate_constellation", req.getMateConstellation());
        }

        if (!StrUtil.isEmpty(req.getMateConstellationCn())) {
            queryWrapper.like("mate_constellation_cn", req.getMateConstellationCn());
        }

        if (!StrUtil.isEmpty(req.getMateWeight())) {
            queryWrapper.like("mate_weight", req.getMateWeight());
        }

        if (null != req.getMateWeightMin()) {
            queryWrapper.eq("mate_weight_min", req.getMateWeightMin());
        }

        if (null != req.getMateWeightMax()) {
            queryWrapper.eq("mate_weight_max", req.getMateWeightMax());
        }

        if (null != req.getMateMarry()) {
            queryWrapper.eq("mate_marry", req.getMateMarry());
        }

        if (!StrUtil.isEmpty(req.getMateMarryCn())) {
            queryWrapper.like("mate_marry_cn", req.getMateMarryCn());
        }

        if (null != req.getMateNationality()) {
            queryWrapper.eq("mate_nationality", req.getMateNationality());
        }

        if (!StrUtil.isEmpty(req.getMateNationalityCn())) {
            queryWrapper.like("mate_nationality_cn", req.getMateNationalityCn());
        }

        if (null != req.getMateHouse()) {
            queryWrapper.eq("mate_house", req.getMateHouse());
        }

        if (!StrUtil.isEmpty(req.getMateHouseCn())) {
            queryWrapper.like("mate_house_cn", req.getMateHouseCn());
        }

        if (null != req.getMateCar()) {
            queryWrapper.eq("mate_car", req.getMateCar());
        }

        if (!StrUtil.isEmpty(req.getMateCarCn())) {
            queryWrapper.like("mate_car_cn", req.getMateCarCn());
        }

        if (null != req.getMateIndustry()) {
            queryWrapper.eq("mate_industry", req.getMateIndustry());
        }

        if (!StrUtil.isEmpty(req.getMateIndustryCn())) {
            queryWrapper.like("mate_industry_cn", req.getMateIndustryCn());
        }

        if (null != req.getMateProfession()) {
            queryWrapper.eq("mate_profession", req.getMateProfession());
        }

        if (!StrUtil.isEmpty(req.getMateProfessionCn())) {
            queryWrapper.like("mate_profession_cn", req.getMateProfessionCn());
        }

        if (null != req.getMateDisposition()) {
            queryWrapper.eq("mate_disposition", req.getMateDisposition());
        }

        if (!StrUtil.isEmpty(req.getMateDispositionCn())) {
            queryWrapper.like("mate_disposition_cn", req.getMateDispositionCn());
        }

        if (!StrUtil.isEmpty(req.getMateNativePlace())) {
            queryWrapper.like("mate_native_place", req.getMateNativePlace());
        }

        if (!StrUtil.isEmpty(req.getMateNativePlaceCn())) {
            queryWrapper.like("mate_native_place_cn", req.getMateNativePlaceCn());
        }

        if (null != req.getMateFamilyBackg()) {
            queryWrapper.eq("mate_family_backg", req.getMateFamilyBackg());
        }

        if (!StrUtil.isEmpty(req.getMateFamilyBackgCn())) {
            queryWrapper.like("mate_family_backg_cn", req.getMateFamilyBackgCn());
        }

        if (null != req.getMateDrink()) {
            queryWrapper.eq("mate_drink", req.getMateDrink());
        }

        if (!StrUtil.isEmpty(req.getMateDrinkCn())) {
            queryWrapper.like("mate_drink_cn", req.getMateDrinkCn());
        }

        if (null != req.getMateSmoking()) {
            queryWrapper.eq("mate_smoking", req.getMateSmoking());
        }

        if (!StrUtil.isEmpty(req.getMateSmokingCn())) {
            queryWrapper.like("mate_smoking_cn", req.getMateSmokingCn());
        }

        if (null != req.getMateReligious()) {
            queryWrapper.eq("mate_religious", req.getMateReligious());
        }

        if (!StrUtil.isEmpty(req.getMateReligiousCn())) {
            queryWrapper.like("mate_religious_cn", req.getMateReligiousCn());
        }

        if (null != req.getCreateTime()) {
            queryWrapper.eq("create_time", req.getCreateTime());
        }

        if (null != req.getMotifyTime()) {
            queryWrapper.eq("motify_time", req.getMotifyTime());
        }
        IPage<BcSingleMates> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(BcSingleMates req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public boolean pcModifyMate(BcSingleMates req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", req.getUserId());
        baseMapper.update(req, queryWrapper);
        return false;
    }
}
